package eerbaar.position.internal;

import eerbaar.position.IFrozenPosition;
import eerbaar.position.IPosition;

public class FrozenPosition implements IFrozenPosition {

    private final int x;

    private final int y;

    public FrozenPosition(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public FrozenPosition(IPosition copy) {
        this.x = copy.getX();
        this.y = copy.getY();
    }

    @Override
    public boolean equals(Object obj) {

        int otherX = -1;
        int otherY = -1;

        if (obj instanceof IPosition) {

            IPosition other = (IPosition) obj;
            otherX = other.getX();
            otherY = other.getY();
        }

        if (obj instanceof IFrozenPosition) {

            IFrozenPosition other = (IFrozenPosition) obj;
            otherX = other.getX();
            otherY = other.getY();
        }

        return (otherX == this.x && otherY == this.y);
    }

    @Override
    public int getX() {
        return this.x;
    }

    @Override
    public int getY() {
        return this.y;
    }

    @Override
    public int hashCode() {

        return toString().hashCode();
    }

    @Override
    public String toString() {

        return "position(" + this.x + "," + this.y + ")";
    }
}
